package com.kedll.library.widget;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;

/**
 * @author QiQi
 * @ClassName: SecretTextView
 * @date 2018/9/21
 * @description
 */
public class SecretTextView extends android.support.v7.widget.AppCompatTextView {
    public SecretTextView(Context context) {
        super(context);
    }

    public SecretTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public SecretTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public void setText(String text) {
        if (TextUtils.isEmpty(text)) {
            return;
        }
        char[] chars = text.toCharArray();
        if (chars.length > 4) {
            int start = (chars.length - 4) / 2;
            for (int i = start; i < start + 4; i++) {
                chars[i] = '*';
            }
            super.setText(chars, 0, chars.length);
        } else {
            super.setText(text);
        }

    }
}
